//
//  SecondViewController.m
//  WeiMo
//
//  Created by weixian he on 12-8-18.
//  Copyright (c) 2012年 . All rights reserved.
//

#import "SecondViewController.h"

#import "ThreeImageCell.h"
#import "TouchImageView.h"
#import "KeyValueObject.h"
#import "UIImageView+WebCache.h"
#import "AGImagePickerController.h"
#import "AGIPCToolbarItem.h"
#import "SDImageCache.h"
#import "DLog.h"
#import "InterfaceDefine.h"
#import "JSONKit.h"
#import "FMManager.h"
#import "MBProgressHUD.h"
#import "AutoContentCell.h"
#import <QuartzCore/QuartzCore.h>
#import "FMManager.h"
#import "EditViewController.h"
#import "SVPullToRefresh.h"
#import "LoginViewController.h"
#import "SDImageCache.h"
#import "PersonalHeadShowCell.h"
#import "BubbleChatViewController.h"
#import "SFHFKeychainUtils.h"


#define kImageIntNums 4
#define kImageViewTagBase 10
#define kSpaceLarge (@"        ")
#define kSapceSmall (@"   ")
#define kStartString (@" ******")

/*
 section 0 cell 图片
 section 1 cell 姓名 到 所属公司
 section 2 header 个人风格 一个cell 刚毅，阳光
 section 3 header 个人/企业介绍 一个cell 喜欢xxxx
 section 4 header 工作联系方式 cell 工作联系电话，
 section 5 header 演出经历 一个cell xxxxx
 */

@interface SecondViewController ()
{
    MBProgressHUD *mHUD;
}

/*
 keyDispName:小图url
 */
@property(nonatomic,retain) NSTimer *timer;
@property(nonatomic,retain) KeyValueObject *headerDatas;
@property(nonatomic,retain) NSMutableArray *section0list; //<KeyValueObject>
@property(nonatomic,retain) NSMutableArray *section1List; //NSString
@property(nonatomic,retain) NSMutableArray *section2List; //NSString
@property(nonatomic,retain) NSMutableArray *section3List; //NSString
@property(nonatomic,retain) NSMutableArray *section4List; //NSString
@property(nonatomic,retain) NSMutableArray *section5List; //NSString

@property(nonatomic,retain) NSDictionary *dicSection; //所有数据

@property (nonatomic, retain) NSMutableArray *photos; //<MWPhoto>

@property(nonatomic,retain) UILabel *section2headerView;
@property(nonatomic,retain) UILabel *section3headerView;
@property(nonatomic,retain) UILabel *section4headerView;
@property(nonatomic,retain) UILabel *section5headerView;

@property(nonatomic, retain) NSMutableArray *selectedPhotos; //选择图片

@property(nonatomic,retain) UILabel *cityLabel;
@property(nonatomic,retain) UILabel *pointLabel1;
@property(nonatomic,retain) UILabel *pointLabel2;
@property(nonatomic,retain) UILabel *heightLabel;
@property(nonatomic,retain) UILabel *weightLabel;
@property(nonatomic,retain) UILabel *barLabel;
@end

@implementation SecondViewController
@synthesize editType,tempKey,tempNum,modelName,modelId;

@synthesize section0list,section1List,section2List,section3List,section4List,section5List;

@synthesize dicSection;
@synthesize photos;
@synthesize selectedPhotos;

@synthesize section2headerView,section3headerView,section4headerView,section5headerView;

@synthesize cityLabel,pointLabel1,pointLabel2,heightLabel,weightLabel,barLabel;

@synthesize timer;

@synthesize userIdentify;
@synthesize headerDatas;

@synthesize hadDataDic;

-(void)dealloc
{
    self.editType = nil;
    self.tempKey = nil;
    self.tempNum = nil;
    self.modelName = nil;
    self.modelId = nil;
    self.section0list = nil;
    self.section1List = nil;
    self.section2List = nil;
    self.section3List = nil;
    self.section4List = nil;
    self.section5List = nil;
    self.dicSection = nil;
    self.photos = nil;
    self.selectedPhotos = nil;
    self.section2headerView = nil;
    self.section3headerView = nil;
    self.section4headerView = nil;
    self.section5headerView = nil;
    self.cityLabel = nil;
    self.pointLabel1 = nil;
    self.pointLabel2 = nil;
    self.heightLabel = nil;
    self.weightLabel = nil;
    self.barLabel = nil;
    [self.timer invalidate];
    self.timer = nil;
    self.userIdentify = nil;
    self.headerDatas = nil;
    self.hadDataDic = nil;
    [super dealloc];
}

- (id)init
{
    self = [super init];
    if (self)
    {
        self.title = NSLocalizedString(@"我的资料", @"我的资料");
        self.tabBarItem.image = [UIImage imageNamed:@"my"];
    }
    return self;
}
							
- (void)viewDidLoad
{
    [super viewDidLoad];
    
    [[UIBarButtonItem appearance] setTintColor:[UIColor blackColor]];
    
    if([self.editType isEqualToString:@"isMy"])
    {
        self.title = @"我的资料";
        self.modelId = [[FMManager sharedInstance] userId];
    }
    else
    {
        self.title = @"个人资料";
    }
    
    self.tableView.showsVerticalScrollIndicator = NO;
    //self.tableView.backgroundColor = [UIColor colorWithRed:236.0/255 green:237.0/255 blue:241.0/255 alpha:1];
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    
    //上拉事件
    [self.tableView addPullToRefreshWithActionHandler:^{
        self.timer = [NSTimer scheduledTimerWithTimeInterval:0.8 target:self selector:@selector(getPersonalMessageDatas) userInfo:nil repeats:NO];
    }];
    
    [self initSectionHeaderView];
}


-(void)myRefeash
{
    FMManager *fm =[FMManager sharedInstance];
    
    if(fm.updateSecondCtrl)
    {
        if ([self.editType isEqualToString:@"isMy"])
        {
            self.userIdentify = fm.modeIdentify;
            self.userId = fm.userId;
            UIBarButtonItem *rightButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"编辑" style:UIBarButtonItemStyleBordered target:self action:@selector(goToFirstEditSelfMessage:)];
            self.navigationItem.rightBarButtonItem = rightButtonItem;
            [rightButtonItem release];
        }
        else if(self.userId && ![self.userId isEqualToString:fm.userId])
        {
            UIBarButtonItem *rightButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"私信" style:UIBarButtonItemStyleBordered target:self action:@selector(goToSendMessageEvent)];
            self.navigationItem.rightBarButtonItem = rightButtonItem;
            [rightButtonItem release];
        }
        
        fm.updateSecondCtrl=FALSE;
        self.section0list = nil;
        mHUD = [[MBProgressHUD alloc] initWithView:self.navigationController.view];
        [self.navigationController.view addSubview:mHUD];
        mHUD.delegate = self;
        [self getPersonalMessageDatas];
        [mHUD show:YES];
    }
    else
    {
        if ([self.editType isEqualToString:@"isMy"])
        {
            self.userIdentify = fm.modeIdentify;
            self.userId = fm.userId;
            
            NSString *personalMessages = [FMManager getPersonalMessageFromLocal];
            if (personalMessages && personalMessages.length > 0)
            {
                [self getPersonalDatasFromFMManager:personalMessages];
            }
            else
            {
                mHUD = [[MBProgressHUD alloc] initWithView:self.navigationController.view];
                [self.navigationController.view addSubview:mHUD];
                mHUD.delegate = self;
                [self getPersonalMessageDatas];
                [mHUD show:YES];
            }
            
            UIBarButtonItem *rightButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"编辑" style:UIBarButtonItemStyleBordered target:self action:@selector(goToFirstEditSelfMessage:)];
            self.navigationItem.rightBarButtonItem = rightButtonItem;
            [rightButtonItem release];
        }
        else 
        {
            if(self.userId && ![self.userId isEqualToString:fm.userId])
            {
                UIBarButtonItem *rightButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"私信" style:UIBarButtonItemStyleBordered target:self action:@selector(goToSendMessageEvent)];
                self.navigationItem.rightBarButtonItem = rightButtonItem;
                [rightButtonItem release];
            }
                        
            if(self.hadDataDic)
            {
                [self updateModelInfo:hadDataDic];
            }
            else
            {
                mHUD = [[MBProgressHUD alloc] initWithView:self.navigationController.view];
                [self.navigationController.view addSubview:mHUD];
                mHUD.delegate = self;
                [self getPersonalMessageDatas];
                [mHUD show:YES];
            }
        }
    }
}

- (void) viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    [self showSecondTabBar];
}

- (void)viewDidUnload
{
    DEnter();
    [super viewDidUnload];
    self.section2headerView = nil;
    self.section3headerView = nil;
    self.section4headerView = nil;
    self.section5headerView = nil;
    
    [self.timer invalidate];
    self.timer = nil;
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
}

-(void)didReceiveMemoryWarning
{
    DEnter();
    [[SDImageCache sharedImageCache] clearMemory];
    [super didReceiveMemoryWarning];
}

#pragma mark - private methods

//显示TabBar
- (void)showSecondTabBar
{
    if (self.tabBarController.tabBar.hidden == NO)
    {
        return;
    }
    UIView *contentView;
    if ([[self.tabBarController.view.subviews objectAtIndex:0] isKindOfClass:[UITabBar class]])
        
        contentView = [self.tabBarController.view.subviews objectAtIndex:1];
    
    else
        
        contentView = [self.tabBarController.view.subviews objectAtIndex:0];
    contentView.frame = CGRectMake(contentView.bounds.origin.x, contentView.bounds.origin.y,  contentView.bounds.size.width, contentView.bounds.size.height - self.tabBarController.tabBar.frame.size.height);
    self.tabBarController.tabBar.hidden = NO;
    
}

//解析从FMManager获取的数据
- (void)getPersonalDatasFromFMManager:(NSString *)string
{
    NSDictionary *dic = [string objectFromJSONString];
    [self updateDataByDic:dic];
}

//请求数据
-(void)getPersonalMessageDatas
{
    if([self.editType isEqualToString:@"isMy"])
    {
        FMManager *fm = [FMManager sharedInstance];
        self.userId = fm.userId;
        if(self.userId==nil || self.userId.length==0)
        {
            [self.tableView.pullToRefreshView stopAnimating];
            LoginViewController *loginCtrl = [[LoginViewController alloc] init];
            //loginCtrl.delegate = self;
            [loginCtrl initWithStyle:UITableViewStyleGrouped];
            UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:loginCtrl];
            [loginCtrl release];
            //nav.navigationBar.barStyle = UIBarStyleBlack;
            UIImage *navImage = [UIImage imageNamed:@"top.png"];
            if ([nav.navigationBar respondsToSelector:@selector(setBackgroundImage:forBarMetrics:)])
            {
                [nav.navigationBar setBackgroundImage:navImage forBarMetrics:UIBarMetricsDefault];
            }
            else
            {
                UIImageView* imageView = [[[UIImageView alloc] initWithFrame:nav.navigationBar.frame] autorelease];
                imageView.contentMode = UIViewContentModeLeft;
                imageView.image = navImage;
                [nav.navigationBar insertSubview:imageView atIndex:0];
            }
            
            [self.navigationController presentModalViewController:nav animated:YES];
            [nav release];
            return;
        }
    }

    [self getDataInfo];
}

-(void )getDataInfo
{
    NSString *urlStr;
    NSMutableDictionary *coDic = [[[NSMutableDictionary alloc] init] autorelease];
    if([self.userIdentify isEqualToString:@"3"] || [self.userIdentify isEqualToString:@"4"])
    {
        urlStr= [NSString stringWithFormat:@"%@/%@",kHttpHost,kGetEconomicInfoById];
        [coDic setObject:self.userId forKey:@"userId"];
    }
    else
    {
        if([self.editType isEqualToString:@"isMy"] || [self.editType isEqualToString:@"isMsg"])
        {
            urlStr= [NSString stringWithFormat:@"%@/%@",kHttpHost,kGetDataById];
            [coDic setObject:self.userId forKey:@"userId"];
        }
        else 
        {
            urlStr= [NSString stringWithFormat:@"%@/%@",kHttpHost,kGetModelInfoById];
            [coDic setObject:self.modelId forKey:@"modelsId"];
        }
        
    }
    
    ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:[NSURL URLWithString:urlStr]];
    NSString *postStr = [coDic JSONString];
    DLog("urlStr = %@",urlStr);
    DLog("postStr = %@",postStr);
    
    [request appendPostData:[postStr dataUsingEncoding:NSUTF8StringEncoding]];
    [request setRequestMethod:@"POST"];
    request.delegate = self;
    [request startAsynchronous];
}


//更新模特资料
-(void)updateModelInfo:(NSDictionary *)datadic
{
    self.section1List = [[[NSMutableArray alloc] init] autorelease];
    self.section2List = [[[NSMutableArray alloc] init] autorelease];
    self.section3List = [[[NSMutableArray alloc] init] autorelease];
    self.section4List = [[[NSMutableArray alloc] init] autorelease];
    self.section5List = [[[NSMutableArray alloc] init] autorelease];
    
    self.dicSection = datadic;
    
    NSString *modelsPhotostr = [datadic objectForKey:@"modelsPhotostr"];
    
    //section 0 图片
    if(![modelsPhotostr isEqualToString:@""])
    {
        NSArray *strPhotos = [modelsPhotostr componentsSeparatedByString:@";"];
        NSMutableArray *tempArray = [[[NSMutableArray alloc] init] autorelease];
        
        //头像、姓名、职业
        NSString *modelsName = [datadic objectForKey:@"modelsName"];
        //职业
        NSString *modelsBloodtype= [datadic objectForKey:@"modelsBloodtype"];
        modelsBloodtype = [NSString stringWithFormat:@"职业/职位: %@",modelsBloodtype];
        self.headerDatas = [[[KeyValueObject alloc] init] autorelease];
        self.headerDatas.keyDispName = modelsName;
        self.headerDatas.valueDispName = [NSString stringWithFormat:@"%@/%@/%@/small_%@",kHttpHost,@"photo",self.userId,[strPhotos objectAtIndex:0]];
        self.headerDatas.value = modelsBloodtype;
        
        /*
         canClick:推荐
         isCheck:预约
         key:用户id
         keyDispName:小图url
         */
        for( int i=0; i<strPhotos.count; i++)
        {
            KeyValueObject *item = [[KeyValueObject alloc] init];
            item.canClick = YES;
            item.isCheck = NO;
            item.key = [NSString stringWithFormat:@"%d",i];
            
            NSString *imageUrl = [NSString stringWithFormat:@"%@/%@/%@/small_%@",kHttpHost,@"photo",self.userId,[strPhotos objectAtIndex:i]];
            DLog(@"imageUrl= %@",imageUrl);
            item.keyDispName = imageUrl;
            [tempArray addObject:item];
            [item release];
        }
        self.section0list = tempArray;
        
        NSMutableArray *photosArray = [[[NSMutableArray alloc] init] autorelease];
        for(int i=0;i<strPhotos.count;i++)
        {
            NSString *temp = [NSString stringWithFormat:@"%@/%@/%@/%@",kHttpHost,@"photo",self.userId,[strPhotos objectAtIndex:i]];
            NSURL *url = [NSURL URLWithString:temp];
            MWPhoto *photoItem = [MWPhoto photoWithURL:url];
            
            //MWPhoto *photo = [MWPhoto photoWithImage:[UIImage imageNamed:item.keyDispName]];
            //photo.caption = item.key;
            [photosArray addObject:photoItem];
        }
        self.photos = photosArray;
    }
    
    //身高
    NSString *height = [datadic objectForKey:@"modelsHeight"];
    height = [NSString stringWithFormat:@" 身高: %@cm",height];
    [self.section1List addObject:height];
    
    NSString *weight = [datadic objectForKey:@"modelsWeight"];
    weight = [NSString stringWithFormat:@" 体重: %@kg",weight];
    [self.section1List addObject:weight];
    
    NSString *modelsMeasurements =[datadic objectForKey:@"modelsMeasurements"]; //数据不对
    modelsMeasurements = [NSString stringWithFormat:@" 三围: %@",modelsMeasurements];
    [self.section1List addObject:modelsMeasurements];
    
    NSString *modelsJks = [datadic objectForKey:@"modelsJks"];
    modelsJks = [NSString stringWithFormat:@" 肩宽: %@",modelsJks];
    [self.section1List addObject:modelsJks];
    
    //鞋码   肩宽没有
    NSString *modelsSize = [datadic objectForKey:@"modelsSize"];
    modelsSize = [NSString stringWithFormat:@" 鞋码：%@",modelsSize];
    [self.section1List addObject:modelsSize];
    
    //现居城市
    NSString *modelsAddress = [datadic objectForKey:@"modelsAddress"];
    NSString *city = [NSString stringWithFormat:@" 所在城市: %@",modelsAddress];
    [self.section1List addObject:city];
    
    //所属公司
    NSString *modelsSsgs = [datadic objectForKey:@"modelsSsgs"];
    NSString *strCom = [NSString stringWithFormat:@" 所属公司: %@",modelsSsgs];
    [self.section1List addObject:strCom];
    
    
    //个人风格
    NSString *modelsStyle = [datadic objectForKey:@"modelsStyle"];
    if([modelsStyle isEqualToString:@""])
    {
        modelsStyle=@"这个人很懒，暂无数据";
    }
    [self.section2List addObject:modelsStyle];
    
    //个人/公司介绍
    NSString *modelsPersent = [datadic objectForKey:@"modelsPersent"];
    if([modelsPersent isEqualToString:@""])
    {
        modelsPersent=@"这个人很懒，暂无数据";
    }
    [self.section3List addObject:modelsPersent];
    
    //工作联系方式
    //工作联系电话
    NSString *modelsPhone = kStartString;
    if([self.editType isEqualToString:@"isWorker"])
    {
        modelsPhone = [datadic objectForKey:@"modelsPhone"];
    }
    else
    {
        modelsPhone = kStartString;
    }
    
    modelsPhone = [NSString stringWithFormat:@" 工作电话: %@",modelsPhone];
    [self.section4List addObject:modelsPhone];
    
    //工作邮箱
    NSString *modelsEmail = kStartString;
    if([self.editType isEqualToString:@"isWorker"])
    {
        modelsEmail = [datadic objectForKey:@"modelsEmail"];
    }
    else
    {
        modelsEmail = kStartString;
    }
    modelsEmail = [NSString stringWithFormat:@" 工作邮箱: %@",modelsEmail];
    [self.section4List addObject:modelsEmail];
    
//    //工作QQ
//    NSString *modelsQq = kStartString;
//    if([self.editType isEqualToString:@"isWorker"])
//    {
//        modelsQq = [datadic objectForKey:@"modelsQq"];
//    }
//    else
//    {
//        modelsQq = kStartString;
//    }
//    modelsQq = [NSString stringWithFormat:@" 工作QQ: %@",modelsQq];
//    [self.section4List addObject:modelsQq];
//    
//    //工作微信
//    NSString *modelsVx = kStartString;
//    if([self.editType isEqualToString:@"isWorker"])
//    {
//        modelsVx = [datadic objectForKey:@"modelsVx"];
//    }
//    else
//    {
//        modelsVx = kStartString;
//    }
//    
//    modelsVx = [NSString stringWithFormat:@" 工作微信: %@",modelsVx];
//    [self.section4List addObject:modelsVx];
    
    
    //演出经历
    NSString *modelsExperience = [datadic objectForKey:@"modelsExperience"];
    if([modelsExperience isEqualToString:@""])
    {
        modelsExperience=@"这个人很懒，暂无数据";
    }
    [self.section5List addObject:modelsExperience];
    
    [self.tableView reloadData];
}

//更新经纪人资料
-(void)updateEconomicInfo:(NSDictionary *)datadic
{
    self.dicSection = datadic;
    
    //NSString *modelsPhotostr = [datadic objectForKey:@"economicPhotostr"];
    
//    NSArray *modelsList = [datadic objectForKey:@"modelsList"];
//    
//    self.section0list = [[[NSMutableArray alloc] init] autorelease];
//    
//    //section 0 图片
//    if(modelsList && modelsList.count > 0)
//    {
//        for( int i=0; i<modelsList.count; i++)
//        {
//            KeyValueObject *item = [[KeyValueObject alloc] init];
//            item.canClick = YES;
//            item.isCheck = NO;
//            item.key = [NSString stringWithFormat:@"%d",i];
//            
//            NSDictionary *dicdata = [modelsList objectAtIndex:i];
//            NSString *imageUrl = [NSString stringWithFormat:@"%@/%@/%@/%@",kHttpHost,@"photo",self.userId,[dicdata objectForKey:@"modelsAvatarstr"]];
//            item.keyDispName = imageUrl;
//            [self.section0list addObject:item];
//            [item release];
//        }
//    }

    NSString *modelsPhotostr = [datadic objectForKey:@"economicPhotostr"];
    
    //section 0 图片
    if(![modelsPhotostr isEqualToString:@""])
    {
        NSArray *strPhotos = [modelsPhotostr componentsSeparatedByString:@";"];
        NSMutableArray *tempArray = [[[NSMutableArray alloc] init] autorelease];
        
        /*
         canClick:推荐
         isCheck:预约
         key:用户id
         keyDispName:小图url
         */
        for( int i=0; i<strPhotos.count; i++)
        {
            KeyValueObject *item = [[KeyValueObject alloc] init];
            item.canClick = YES;
            item.isCheck = NO;
            item.key = [NSString stringWithFormat:@"%d",i];
            
            NSString *imageUrl = [NSString stringWithFormat:@"%@/%@/%@/small_%@",kHttpHost,@"photo",self.userId,[strPhotos objectAtIndex:i]];
            DLog(@"imageUrl= %@",imageUrl);
            item.keyDispName = imageUrl;
            [tempArray addObject:item];
            [item release];
        }
        self.section0list = tempArray;
        
        NSMutableArray *photosArray = [[[NSMutableArray alloc] init] autorelease];
        for(int i=0;i<strPhotos.count;i++)
        {
            NSString *temp = [NSString stringWithFormat:@"%@/%@/%@/%@",kHttpHost,@"photo",self.userId,[strPhotos objectAtIndex:i]];
            NSURL *url = [NSURL URLWithString:temp];
            MWPhoto *photoItem = [MWPhoto photoWithURL:url];
            
            //MWPhoto *photo = [MWPhoto photoWithImage:[UIImage imageNamed:item.keyDispName]];
            //photo.caption = item.key;
            [photosArray addObject:photoItem];
        }
        self.photos = photosArray;
    }
    
    //头像、姓名、职业
    NSString *modelsName = [datadic objectForKey:@"economicName"];
    //职业
    NSString *modelsBloodtype= [datadic objectForKey:@"economicBloodtype"];
    modelsBloodtype = [NSString stringWithFormat:@"职业/职位: %@",modelsBloodtype];
    self.headerDatas = [[[KeyValueObject alloc] init] autorelease];
    self.headerDatas.keyDispName = modelsName;

    NSString *economicAvatarstr = [datadic objectForKey:@"economicAvatarstr"];
    if(economicAvatarstr && economicAvatarstr.length > 0)
    {
        self.headerDatas.valueDispName = [NSString stringWithFormat:@"%@/%@/%@/small_%@",kHttpHost,@"photo",self.userId,economicAvatarstr];
    }
    self.headerDatas.value = modelsBloodtype;

    self.section1List = [[[NSMutableArray alloc] init] autorelease];
    //现居城市
    NSString *modelsAddress = [datadic objectForKey:@"economicAddress"];
    NSString *city = [NSString stringWithFormat:@" 所在城市: %@",modelsAddress];
    [self.section1List addObject:city];
    
    //所属公司
    NSString *modelsSsgs = [datadic objectForKey:@"economicSsgs"];
    NSString *strCom = [NSString stringWithFormat:@" 所属公司: %@",modelsSsgs];
    [self.section1List addObject:strCom];
    
    
    //个人风格
    self.section2List = [[[NSMutableArray alloc] init] autorelease];
    
    NSString *modelsStyle = [datadic objectForKey:@"economicStyle"];
    if([modelsStyle isEqualToString:@""])
    {
        modelsStyle=@"这个人很懒，暂无数据";
    }
    [self.section2List addObject:modelsStyle];
    
    //个人/公司介绍
    self.section3List = [[[NSMutableArray alloc] init] autorelease];
    
    NSString *modelsPersent = [datadic objectForKey:@"economicPersent"];
    if([modelsPersent isEqualToString:@""])
    {
        modelsPersent=@"这个人很懒，暂无数据";
    }
    [self.section3List addObject:modelsPersent];
    
    //工作联系方式
    //工作联系电话
    self.section4List = [[[NSMutableArray alloc] init] autorelease];
    
    NSString *modelsPhone = kStartString;
    if([self.editType isEqualToString:@"isWorker"])
    {
        modelsPhone = [datadic objectForKey:@"economicPhone"];
    }
    else
    {
        modelsPhone = kStartString;
    }
    
    modelsPhone = [NSString stringWithFormat:@" 工作电话: %@",modelsPhone];
    [self.section4List addObject:modelsPhone];
    
    //工作邮箱
    NSString *modelsEmail = kStartString;
    if([self.editType isEqualToString:@"isWorker"])
    {
        modelsEmail = [datadic objectForKey:@"economicEmail"];
    }
    else
    {
        modelsEmail = kStartString;
    }
    modelsEmail = [NSString stringWithFormat:@" 工作邮箱: %@",modelsEmail];
    [self.section4List addObject:modelsEmail];
    
//    //工作QQ
//    NSString *modelsQq = kStartString;
//    if([self.editType isEqualToString:@"isWorker"])
//    {
//        modelsQq = [datadic objectForKey:@"economicQq"];
//    }
//    else
//    {
//        modelsQq = kStartString;
//    }
//    modelsQq = [NSString stringWithFormat:@" 工作QQ: %@",modelsQq];
//    [self.section4List addObject:modelsQq];
//    
//    //工作微信
//    NSString *modelsVx = kStartString;
//    if([self.editType isEqualToString:@"isWorker"])
//    {
//        modelsVx = [datadic objectForKey:@"economicVx"];
//    }
//    else
//    {
//        modelsVx = kStartString;
//    }
//    
//    modelsVx = [NSString stringWithFormat:@" 工作微信: %@",modelsVx];
//    [self.section4List addObject:modelsVx];
    
    
    //演出经历
    self.section5List = [[[NSMutableArray alloc] init] autorelease];
    
    NSString *modelsExperience = [datadic objectForKey:@"economicExperience"];
    if([modelsExperience isEqualToString:@""])
    {
        modelsExperience=@"这个人很懒，暂无数据";
    }
    [self.section5List addObject:modelsExperience];
    
    [self.tableView reloadData];
}

-(void)updateDataByDic:(NSDictionary *)datadic
{
    if([self.userIdentify isEqualToString:@"3"] || [self.userIdentify isEqualToString:@"4"])
    {
        [self updateEconomicInfo:datadic];
    }
    else
    {
        [self updateModelInfo:datadic];
    }
}

-(void)initSectionHeaderView
{
    self.section2headerView = [[[UILabel alloc] initWithFrame:CGRectMake(0, 0, 320, 28)] autorelease];
    self.section2headerView.text = @"  个人风格";
    self.section2headerView.backgroundColor = [UIColor colorWithRed:223.0/255.0 green:223.0/255.0 blue:223.0/255.0 alpha:1];
    self.section2headerView.textColor = [UIColor colorWithRed:65.0/255 green:65.0/255 blue:65.0/255 alpha:1];
    
    self.section3headerView = [[[UILabel alloc] initWithFrame:CGRectMake(0, 0, 320, 28)] autorelease];
    self.section3headerView.text = @"  个人/企业介绍";
    self.section3headerView.backgroundColor = [UIColor colorWithRed:223.0/255.0 green:223.0/255.0 blue:223.0/255.0 alpha:1];
    self.section3headerView.textColor = [UIColor colorWithRed:65.0/255 green:65.0/255 blue:65.0/255 alpha:1];
    
    
    self.section4headerView = [[[UILabel alloc] initWithFrame:CGRectMake(0, 0, 320, 28)] autorelease];
    self.section4headerView.text = @"  联系方式(发送资料显示)";
    self.section4headerView.backgroundColor = [UIColor colorWithRed:223.0/255.0 green:223.0/255.0 blue:223.0/255.0 alpha:1];
    self.section4headerView.textColor = [UIColor colorWithRed:65.0/255 green:65.0/255 blue:65.0/255 alpha:1];
    
    self.section5headerView = [[[UILabel alloc] initWithFrame:CGRectMake(0, 0, 320, 28)] autorelease];
    self.section5headerView.text = @"  演出经历/企业主营";
    self.section5headerView.backgroundColor = [UIColor colorWithRed:223.0/255.0 green:223.0/255.0 blue:223.0/255.0 alpha:1];
    self.section5headerView.textColor = [UIColor colorWithRed:65.0/255 green:65.0/255 blue:65.0/255 alpha:1];
    
    /*
     self.headerView2 = [[[UILabel alloc] initWithFrame:CGRectMake(0, 0, 320, 28)] autorelease];
     self.headerView2.text = @"   风格特点";
     self.headerView2.backgroundColor = [UIColor colorWithRed:223.0/255.0 green:223.0/255.0 blue:223.0/255.0 alpha:1];
     self.headerView2.textColor = [UIColor colorWithRed:65.0/255 green:65.0/255 blue:65.0/255 alpha:1];
     */
}

- (CGSize)returnRectWithString:(NSString *)string andWidth:(float )width
{
    //UIFont *font = [UIFont fontWithName:@"Helvetia-Bold" size:11.5];
    UIFont *font=[UIFont systemFontOfSize:14.5];
    CGSize size = [string sizeWithFont:font constrainedToSize:CGSizeMake(width, 1000) lineBreakMode:NSLineBreakByTruncatingTail];
    return size;
}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 6;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if(section == 0)
    {
        if(self.section0list)
        {
            int mol = self.section0list.count % kImageIntNums;
            int size = ([self.section0list count] )/kImageIntNums + 1;
            if(mol == 0)
            {
                size--;
            }
            return (size + 1);
        }
        else
        {
            return 0;
        }
       
    }
    else if(section == 1)
    {
        if(self.section1List)
        {
            return self.section1List.count;
        }
        else
        {
            return 0;
        }
    }
    else if(section == 2)
    {
        if(self.section2List)
        {
            return self.section2List.count;
        }
        else
        {
            return 0;
        }
    }
    else if(section == 3)
    {
        if(self.section3List)
        {
            return self.section3List.count;
        }
        else
        {
            return 0;
        }
    }
    else if(section == 4)
    {
        if(self.section4List)
        {
            return self.section4List.count;
        }
        else
        {
            return 0;
        }
    }
    else if(section == 5)
    {
        if(self.section5List)
        {
            return self.section5List.count;
        }
        else
        {
            return 0;
        }
    }
    
    return 0;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    int row = [indexPath row];
    int section = [indexPath section];
    
    if(section == 0)
    {
        if (row == 0)
        {
            static NSString *personalHeaderCell = @"personalHeaderCell";
            PersonalHeadShowCell *cell = [tableView dequeueReusableCellWithIdentifier:personalHeaderCell];
            if (cell == nil)
            {
                cell = [[[PersonalHeadShowCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:personalHeaderCell] autorelease];
                cell.selectionStyle = UITableViewCellSelectionStyleNone;
            }
            
            [cell.headerImageView setImageWithURL:[NSURL URLWithString:self.headerDatas.valueDispName] placeholderImage:[UIImage imageNamed:@"touxiang.png"]];
            cell.nameLable.text = self.headerDatas.keyDispName;
            cell.professionLable.text = self.headerDatas.value;
            DLog(@"headurl : %@",self.headerDatas.valueDispName);
            return cell;
        }
        else
        {
            static NSString *personalCellIdentifier0 = @"personalCellIdentifier0";
            ThreeImageCell *cell = [tableView dequeueReusableCellWithIdentifier:personalCellIdentifier0];
            if(cell == nil)
            {
                cell = [[[ThreeImageCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:personalCellIdentifier0 canCheck:NO] autorelease];
                cell.selectionStyle = UITableViewCellSelectionStyleNone;
                cell.contentView.backgroundColor = [UIColor colorWithRed:37.0/255 green:37.0/255 blue:37.0/255 alpha:1.0];
            }
            
            int index;
            int listSize = [self.section0list count];
            for( int i = 0; i < kImageIntNums; i++)
            {
                index = (row - 1) *kImageIntNums +i;
                TouchImageView *imageView = [cell.imageViews objectAtIndex:i];
                
                if (row > 1)
                {
                    CGRect rect = imageView.frame;
                    rect.origin.y = 1.0;
                    imageView.frame = rect;
                }
                
                if(index < listSize)
                {
                    KeyValueObject *item = [self.section0list objectAtIndex:index];
                    NSString *imageUrl = item.keyDispName;
                    DLog(@"imageUrl = %@",imageUrl);
                    [imageView setImageWithURL:[NSURL URLWithString:imageUrl]
                              placeholderImage:[UIImage imageNamed:@"touxiang.png"]];
                    
                    imageView.delegate = self;
                    imageView.tag = index + kImageViewTagBase;
                    imageView.hidden = NO;
                }
                else
                {
                    imageView.hidden = YES;
                }
            }
            
            return cell;
        }
    }
    else if(section == 1)
    {
        static NSString *personalCellIdentifier1 = @"personalCellIdentifier1";
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:personalCellIdentifier1];
        if(cell == nil)
        {
            cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:personalCellIdentifier1] autorelease];
            cell.textLabel.font = [UIFont systemFontOfSize:14.5];//[UIFont fontWithName:@"Helvetia-Bold" size:11.5];
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
            cell.textLabel.contentMode = UIViewContentModeCenter;
        
            UILabel *lineLabel = [[[UILabel alloc] initWithFrame:CGRectMake(0, 33.4,tableView.frame.size.width, 0.6)] autorelease];
            lineLabel.backgroundColor = [UIColor colorWithWhite:0.0 alpha:0.2];
            lineLabel.tag = 10001;
            [cell addSubview:lineLabel];
        }

        cell.textLabel.text = [self.section1List objectAtIndex:row];
        
        UILabel *line = (UILabel *)[cell viewWithTag:10001];
        if(row == self.section1List.count - 1)
        {
            line.hidden = YES;
        }
        else
        {
            line.hidden = NO;
        }
        return cell;
    }
    else if(section == 2 || section == 3 || section == 5)
    {
        static NSString *personalCellIdentifier2 = @"personalCellIdentifier2";
        AutoContentCell *cell = [tableView dequeueReusableCellWithIdentifier:personalCellIdentifier2];
        if(cell == nil)
        {
            cell = [[[AutoContentCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:personalCellIdentifier2] autorelease];
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
        }
        
        if(section == 2)
        {
            [cell reLayout:self.tableView.frame.size.width andContentStr:[self.section2List objectAtIndex:row]];
        }
        else if(section == 3)
        {
            [cell reLayout:self.tableView.frame.size.width andContentStr:[self.section3List objectAtIndex:row]];
        }
        else if(section == 5)
        {
            [cell reLayout:self.tableView.frame.size.width andContentStr:[self.section5List objectAtIndex:row]];
        }
        return cell;
    }
    else if(section == 4)
    {
        static NSString *personalCellIdentifier3 = @"personalCellIdentifier3";
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:personalCellIdentifier3];
        if(cell == nil)
        {
            cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:personalCellIdentifier3] autorelease];
            cell.textLabel.font = [UIFont systemFontOfSize:14.5];//[UIFont fontWithName:@"Helvetia-Bold" size:11.5];
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
            cell.textLabel.contentMode = UIViewContentModeCenter;
            
            /*
            UILabel *lineLabel = [[[UILabel alloc] initWithFrame:CGRectMake(0, 33.4,tableView.frame.size.width, 0.6)] autorelease];
            lineLabel.backgroundColor = [UIColor grayColor];
            lineLabel.tag = 10001;
            [cell addSubview:lineLabel];
             */
        }
        
        cell.textLabel.text = [self.section4List objectAtIndex:row];
        
        /*
        UILabel *line = (UILabel *)[cell viewWithTag:10001];
        if(row == self.section4List.count - 1)
        {
            line.hidden = YES;
        }
        else
        {
            line.hidden = NO;
        }
         */
        return cell;
    }
    return nil;
}

#pragma mark - Table view delegate

-(UIView*)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    if(section == 2)
    {
        if(self.section2List && self.section2List.count > 0)
        {
            return self.section2headerView;
        }
        else
        {
            return nil;
        }
    }
    else if(section == 3)
    {
        if(self.section3List && self.section3List.count > 0)
        {
            return self.section3headerView;
        }
        else
        {
            return nil;
        }
    }
    else if(section == 4)
    {
        if(self.section4List && self.section4List.count > 0)
        {
            return self.section4headerView;
        }
        else
        {
            return nil;
        }
    }
    else if(section == 5)
    {
        if(self.section5List && self.section5List.count > 0)
        {
            return self.section5headerView;
        }
        else
        {
            return nil;
        }
    }
    
    return nil;
}

-(float)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    if(section == 2)
    {
        if(self.section2List && self.section2List.count > 0 && self.section2headerView)
        {
            return self.section2headerView.frame.size.height;
        }
        else
        {
            return 0.0;
        }
    }
    else if(section == 3)
    {
        if(self.section3List && self.section3List.count > 0 && self.section3headerView)
        {
            return self.section3headerView.frame.size.height;
        }
        else
        {
            return 0.0;
        }
    }
    else if(section == 4)
    {
        if(self.section4List && self.section4List.count > 0 && self.section4headerView)
        {
            return self.section4headerView.frame.size.height;
        }
        else
        {
            return 0.0;
        }
    }
    else if(section == 5)
    {
        if(self.section5List && self.section5List.count > 0 && self.section5headerView)
        {
            return self.section5headerView.frame.size.height;
        }
        else
        {
            return 0.0;
        }
    }
    
    return 0.0;
}

-(float)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section == 0)
    {
        if (indexPath.row == 0)
        {
            return 110.0;
        }
        else
        {
            float space = (indexPath.row == 1) ? 6.0 : 4.0;
            return ((tableView.frame.size.width - 10) / 4.0 + space);
        }
    }
    else if( indexPath.section == 2)
    {
        if(self.section2List && self.section2List.count > 0)
        {
            float w = self.tableView.frame.size.width - kContentWidthSpace * 2;
            CGSize size = [self returnRectWithString:[self.section2List objectAtIndex:0] andWidth:w];
            float height = size.height + kContentHeightSpace *2;
            return height;
        }
        else
        {
            return 0;
        }
    }
    else if( indexPath.section == 3)
    {
        if(self.section3List && self.section3List.count > 0)
        {
            float w = self.tableView.frame.size.width - kContentWidthSpace * 2;
            CGSize size = [self returnRectWithString:[self.section3List objectAtIndex:0] andWidth:w];
            float height = size.height + kContentHeightSpace *2;
            return height;
        }
        else
        {
            return 0;
        }
    }
    else if(indexPath.section == 4)
    {
        return 26;
    }
    else if( indexPath.section == 5)
    {
        if(self.section5List && self.section5List.count > 0)
        {
            float w = self.tableView.frame.size.width - kContentWidthSpace * 2;
            CGSize size = [self returnRectWithString:[self.section5List objectAtIndex:0] andWidth:w];
            float height = size.height + kContentHeightSpace *2;
            return height;
        }
        else
        {
            return 0;
        }
    }
    else
    {
        return 34;
    }
}

#pragma mark - button event

-(void)addMyku:(id)sender
{
    
}


-(void)toSeeImageByIndex:(NSUInteger )index
{
    // Create browser
	MWPhotoBrowser *browser = [[MWPhotoBrowser alloc] initWithDelegate:self];
    [browser setInitialPageIndex:index];
    //browser.displayActionButton = YES;
    
    // Show
    if (0) {
        // Push
        [self.navigationController pushViewController:browser animated:YES];
    } else {
        // Modal
        UINavigationController *nc = [[UINavigationController alloc] initWithRootViewController:browser];
        nc.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
        [self presentModalViewController:nc animated:YES];
        [nc release];
    }
    
    [browser release];
}

-(void)toAddImage
{
    AGImagePickerController *imagePickerController = [[AGImagePickerController alloc] initWithFailureBlock:^(NSError *error) {
        //NSLog(@"Fail. Error: %@", error);
        
        if (error == nil) {
            [self.selectedPhotos removeAllObjects];
            //NSLog(@"User has cancelled.");
            [self dismissModalViewControllerAnimated:YES];
        } else {
            
            // We need to wait for the view controller to appear first.
            double delayInSeconds = 0.5;
            dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, delayInSeconds * NSEC_PER_SEC);
            dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
                [self dismissModalViewControllerAnimated:YES];
            });
        }
        
        [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleDefault animated:YES];
        
    } andSuccessBlock:^(NSArray *info) {
        [self.selectedPhotos setArray:info];
        
        //添加图片
        for(ALAsset *item in info)
        {
            NSURL *url = item.defaultRepresentation.url;
            //NSLog(@"url = %@",url);
            //NSLog(@"Info: %@", info);
            UIImage *addImage = [UIImage imageWithCGImage:item.thumbnail];
            [[SDImageCache sharedImageCache] storeImage:addImage forKey:[url absoluteString]];
            {
                KeyValueObject *obj = [[[KeyValueObject alloc] init] autorelease];
                obj.canClick = YES;
                obj.isCheck = NO;
                obj.key = @"00001";
                obj.keyDispName = [url absoluteString];
                if(self.section0list && (self.section0list.count != 0))
                {
                    [self.section0list insertObject:obj atIndex:(self.section0list.count - 1)];
                }
                else {
                    self.section0list = [[[NSMutableArray alloc] init] autorelease];
                    [self.section0list addObject:obj];
                }
                
                NSURL *url = [NSURL URLWithString:obj.keyDispName];
                MWPhoto *photo = [MWPhoto photoWithURL:url];
                photo.caption = obj.key;
                [self.photos addObject:photo];
                [self.tableView reloadData];
            }
        }
        
        [self dismissModalViewControllerAnimated:YES];
        
        [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleDefault animated:YES];
    }];
    
    // Show saved photos on top
    imagePickerController.shouldShowSavedPhotosOnTop = YES;
    imagePickerController.selection = self.selectedPhotos;
    
    // Custom toolbar items
    AGIPCToolbarItem *selectAll = [[AGIPCToolbarItem alloc] initWithBarButtonItem:[[[UIBarButtonItem alloc] initWithTitle:@"全选" style:UIBarButtonItemStyleBordered target:nil action:nil] autorelease] andSelectionBlock:^BOOL(NSUInteger index, ALAsset *asset) {
        return YES;
    }];
    AGIPCToolbarItem *flexible = [[AGIPCToolbarItem alloc] initWithBarButtonItem:[[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil] autorelease] andSelectionBlock:nil]; 
    /*
     AGIPCToolbarItem *selectOdd = [[AGIPCToolbarItem alloc] initWithBarButtonItem:[[[UIBarButtonItem alloc] initWithTitle:@"+ Select Odd" style:UIBarButtonItemStyleBordered target:nil action:nil] autorelease] andSelectionBlock:^BOOL(NSUInteger index, ALAsset *asset) {
     return !(index % 2);
     }];
     */
    AGIPCToolbarItem *deselectAll = [[AGIPCToolbarItem alloc] initWithBarButtonItem:[[[UIBarButtonItem alloc] initWithTitle:@"取消" style:UIBarButtonItemStyleBordered target:nil action:nil] autorelease] andSelectionBlock:^BOOL(NSUInteger index, ALAsset *asset) {
        return NO;
    }];  
    imagePickerController.toolbarItemsForSelection = [NSArray arrayWithObjects:selectAll, flexible, /*selectOdd, flexible, */deselectAll, nil];
    //    imagePickerController.toolbarItemsForSelection = [NSArray array];
    //[selectOdd release];
    [flexible release];
    [selectAll release];
    [deselectAll release];
    
    //    imagePickerController.maximumNumberOfPhotos = 3;
    [self presentModalViewController:imagePickerController animated:YES];
    [imagePickerController release];
}

-(void)goToFirstEditSelfMessage:(id)sender
{
    if([self.userIdentify isEqualToString:@"3"] || [self.userIdentify isEqualToString:@"4"])
    {
        EditViewController2 *ctrl = [[[EditViewController2 alloc] init] autorelease];
        ctrl.delegate = self;
        //[ctrl initWithStyle:UITableViewStyleGrouped];
        ctrl.dataDic = [NSMutableDictionary dictionaryWithDictionary:self.dicSection];
        ctrl.title = @"编辑";
        [self.navigationController pushViewController:ctrl animated:YES];
    }
    else
    {
        EditViewController *ctrl = [[[EditViewController alloc] init] autorelease];
        ctrl.delegate = self;
        //[ctrl initWithStyle:UITableViewStyleGrouped];
        ctrl.dataDic = [NSMutableDictionary dictionaryWithDictionary:self.dicSection];
        ctrl.title = @"编辑";
        [self.navigationController pushViewController:ctrl animated:YES];
    }
}

//发送私信
- (void)goToSendMessageEvent
{
    NSNumber *toUseridStr = [self.dicSection objectForKey:@"userId"];
    NSString *userName =[self.dicSection objectForKey:@"modelsName"];
    BubbleChatViewController *chatViewCtrl = [[[BubbleChatViewController alloc] init] autorelease];
    chatViewCtrl.toUserId = [NSString stringWithFormat:@"%@",toUseridStr];
    chatViewCtrl.toUserImageUrl = self.headerDatas.valueDispName;
    chatViewCtrl.title = userName;
    [self.navigationController pushViewController:chatViewCtrl animated:YES];
}

#pragma mark - TouchImageViewDelegate

-(void)clickImageView:(TouchImageView *)imageView
{
    NSUInteger index;
    index = imageView.tag - kImageViewTagBase;
    NSLog(@"tag = %d",index);
	DLog("self.userIdentify = %@",self.userIdentify);
//    if ([self.userIdentify isEqualToString:@"3"] || [self.userIdentify isEqualToString:@"4"])
//    {
//        NSArray *modelsList = [self.dicSection objectForKey:@"modelsList"];
//        NSDictionary *seeModelDic = [modelsList objectAtIndex:index];
//        SecondViewController *seeModelViewCtrl = [[[SecondViewController alloc] init] autorelease];
//        seeModelViewCtrl.modelId = [seeModelDic objectForKey:@"modelsId"];
//        seeModelViewCtrl.userId = self.userId;
//        seeModelViewCtrl.hadDataDic = [NSDictionary dictionaryWithDictionary:seeModelDic];
//        [seeModelViewCtrl myRefeash];
//        [self.navigationController pushViewController:seeModelViewCtrl animated:YES];
//    }
//    else
//    {
//        [self toSeeImageByIndex:index];
//    }
    
    [self toSeeImageByIndex:index];
}

- (void)editListing:(TouchImageView *)imageView
{
    
}

- (void)viewListing:(TouchImageView *)imageView
{
    
}

#pragma mark - MWPhotoBrowserDelegate

- (NSUInteger)numberOfPhotosInPhotoBrowser:(MWPhotoBrowser *)photoBrowser
{
    return self.photos.count;
}

- (MWPhoto *)photoBrowser:(MWPhotoBrowser *)photoBrowser photoAtIndex:(NSUInteger)index
{
    if (index < self.photos.count)
    {
        return [self.photos objectAtIndex:index];
    }
    
    return nil;
}

#pragma mark - EditViewControllerDelegate

-(void) saveData:(NSMutableDictionary *)dic
{
    [self updateDataByDic:dic];
    //[self getPersonalMessageDatas];
}

-(void) refeashData
{
    [self getPersonalMessageDatas];
}

- (void)updateEdit2ModelDatas:(NSMutableDictionary *)datas
{
}

#pragma mark - EditViewControllerDelegate2

-(void) saveData2:(NSMutableDictionary *)dic
{
    [self updateDataByDic:dic];
    //[self getPersonalMessageDatas];
}

-(void) refeashData2
{
    [self getPersonalMessageDatas];
}

#pragma mark - ASIHTTPRequestDelegate

- (void)requestFinished:(ASIHTTPRequest *)request
{
    if(mHUD)
    {
        mHUD.hidden = YES;
    }
    
    [self.tableView.pullToRefreshView stopAnimating];
    //[MBProgressHUD hideHUDForView:self.view animated:YES];
    NSString *urlStr = [NSString stringWithFormat:@"%@",request.url];
    
    NSString *flagStr = @"";
    if (urlStr.length > 0)
    {
        NSArray *array = [urlStr componentsSeparatedByString:@"/"];
        flagStr = [array objectAtIndex:(array.count - 1)];
    }
    DLog(@"%@",flagStr);
    
    NSData *data = [request responseData];
    NSArray *array = [data objectFromJSONData];
    DLog(@"%@",array);
    
    if(array != nil && array.count > 0)
    {
        NSString *item0 = [array objectAtIndex:0];
        if([item0 isEqualToString:kResponseOk])
        {
            NSDictionary *datadic = [array objectAtIndex:1];
            
            if([self.editType isEqualToString:@"isMy"])
            {
                NSString *messageString = [datadic JSONString];
                [FMManager savePersonalMessageToLocal:messageString];
                
                NSString *selfHeadImageUrl = [datadic objectForKey:@"modelsAvatarstr"];
                FMManager *fm = [FMManager sharedInstance];
                fm.userPhotoName = selfHeadImageUrl;
                [SFHFKeychainUtils storeUsername:kUserPhotoName andPassword:selfHeadImageUrl forServiceName:kAppName updateExisting:YES error:nil];
            }
            
            [self updateDataByDic:datadic];
        }
    }        
}

- (void)requestFailed:(ASIHTTPRequest *)request
{
    [self.tableView.pullToRefreshView stopAnimating];
    if(mHUD == nil)
    {
        mHUD = [[MBProgressHUD alloc] initWithView:self.navigationController.view];
        [self.navigationController.view addSubview:mHUD];
        mHUD.delegate = self;
        [mHUD show:YES];
    }
    mHUD.mode =MBProgressHUDModeText;
    mHUD.labelText = @"网络链接失败";
    [mHUD hide:YES afterDelay:1.5];
}

#pragma mark - MBProgressHUDDelegate

- (void)hudWasHidden:(MBProgressHUD *)hud {
	// Remove HUD from screen when the HUD was hidded
	[mHUD removeFromSuperview];
	[mHUD release];
	mHUD = nil;
}

@end